package pr.iceworld.fernando.springbatchquartzlearning.controller;

import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import pr.iceworld.fernando.springbatchquartzlearning.configuration.CronTriggerFactoryBean;

@RestController
public class QuartzResource {
    private Logger LOGGER = LoggerFactory.getLogger(QuartzResource.class);
    @Autowired
    private CronTriggerFactoryBean cronTriggerFactoryBean;


    @RequestMapping(value ="/create", method = RequestMethod.GET)
    public void createTask(Integer taskId,
                           String qs) throws SchedulerException {
        // */5-*-*-*-*-?
        qs = qs.replaceAll("-", " ");
        cronTriggerFactoryBean.createNewTask(qs, taskId);
    }
}
